<template>
  <div style="margin-top: 30px;">
    <!-- <RecomItem :list="list"></RecomItem> -->
    <el-skeleton style="width: 1260px; margin-left:30px;"
                 animated
                 :loading="loading">
      <template slot="template">
        <div class="mains ">
          <el-skeleton-item variant="image"
                            style="width: 180px; height: 190px;border-radius: 10px;" />
          <div class="right mleft-20">
            <el-skeleton-item variant=" rect"
                              style="width: 20%;height: 20px;font-weight: 400;" />
            <div style="display: flex; align-items: center; justify-items: space-between;">
              <el-skeleton-item variant="text"
                                style="width: 30%;margin-top: 10px;height: 20px;" />
            </div>
            <div class="btns">
              <el-skeleton-item variant="button"
                                style="width: 10%;margin-top: 10px;border-radius: 15px;height: 30px;margin-right: 10px;" />
              <el-skeleton-item variant="button"
                                style="width: 10%;margin-top: 10px;border-radius: 15px;height: 30px;margin-right: 10px;" />
              <el-skeleton-item variant="button"
                                style="width: 10%;margin-top: 10px;border-radius: 15px;height: 30px;margin-right: 10px;" />
              <el-skeleton-item variant="button"
                                style="width: 10%;margin-top: 10px;border-radius: 15px;height: 30px;margin-right: 10px;" />

            </div>
            <div class="biaoqian">
              <el-skeleton-item variant=" rect"
                                style="width: 20%;height: 20px;margin-top: 10px;" />
            </div>
            <div class="intro">
              <el-skeleton-item variant=" rect"
                                style="width: 50%;height: 20px;margin-top: 10px;" />
            </div>
          </div>
        </div>
      </template>
      <template>
        <div class="top"
             v-if="list&&!loading">
          <div class="f-left">
            <img :src="list.coverImgUrl"
                 class="img-180 br-8">
          </div>
          <div class="right">
            <div class="title">
              <tag text="歌单"></tag>
              <h2 class="name">{{ list.name }}</h2>
            </div>
            <div class="author"
                 v-show="list.creator">
              <img :src="list.creator.avatarUrl"
                   alt=""
                   v-if="list.creator">
              <p v-if="list.creator">{{ list.creator.nickname }}</p>
              <span>{{ (list.createTime) |dateFormat }}</span>
            </div>
            <div class="buttons">
              <button>
                <svg class="icon cc"
                     aria-hidden="true">
                  <use xlink:href="#icon-shipinbofangshibofang"></use>
                </svg>
                播放全部</button>
              <button class="bofang">
                <svg class="icon cc"
                     aria-hidden="true">
                  <use xlink:href="#icon-shoucang"></use>
                </svg>
                收藏({{  list.subscribedCount|changeNum }})</button>
              <button class="bofang">
                <svg class="icon cc"
                     aria-hidden="true">
                  <use xlink:href="#icon-fenxiang"></use>
                </svg>
                分享({{ list.shareCount |changeNum }})</button>
              <button class="bofang">
                <svg class="icon cc"
                     aria-hidden="true">
                  <use xlink:href="#icon-cangpeitubiao_xiazaipandiandanxiazaidayinmoban"></use>
                </svg>
                下载全部</button>
            </div>
            <div class="biaoqian">
              <span v-if="list.tags!=''">标签 &#8197;:</span>
              <p v-for="(a,index) in list.tags"
                 :key="index">{{ a + '&#8194;'}}</p>
            </div>
            <div class="music">
              <span>歌曲 &#8197;:</span>
              <p style="padding-top:2px">{{ list.trackCount}}</p>
              <span>播放 &#8197;:</span>
              <p>{{ list.playCount|changeNum }}</p>
            </div>
            <div class="intro">
              <span v-if="list.description!=''">简介 &#8197;:</span>
              <p>{{ list.description }}</p>
            </div>
          </div>
        </div>
        <div class="lists ">
          <Menu :menuList="[ '歌曲列表' ,'评论' ,  '收藏者' ]"
                mode="mode"
                @menuClick="chanIndex"
                :commentCount="commentCount"></Menu>
        </div>
        <ItemList :songlist="songlist"
                  v-if="tabIndex==0"></ItemList>
        <comment :type="2"
                 v-if="tabIndex==1"
                 :id="id"></comment>
      </template>
    </el-skeleton>
  </div>
</template>
<script>
import tag from '@/components/simple/Tag.vue'
import comment from '@/components/comment/comment'
import Menu from '@/components/Menu'
import ItemList from '@/pages/HomeItem/ItemList'
import { getPlayListDetail, getTrackAll } from '@/api/RankList'
export default {
  data () {
    return {
      list: {},
      songlist: [],
      id: '',
      loading: '',
      tabIndex: 0,
      commentCount: '',
    }
  },
  components: { ItemList, Menu, comment, tag },
  created () {
    if (this.$route.query.id) {
      this.id = this.$route.query.id
      this.getTrackAll(this.id)
      this.getMusicDetail(this.id)
    }
  },
  methods: {
    chanIndex (index) {
      this.tabIndex = index
    },    // 获取歌单信息
    async getMusicDetail (id) {
      let res = await getPlayListDetail(id)
      this.list = []
      this.list = res.playlist
      console.log(res, '歌单信息')
      this.commentCount = Number(this.list.commentCount)
    },
    // 获取歌单list
    async getTrackAll (id) {
      this.loading = true
      let res = await getTrackAll(id)
      this.songlist = []
      this.songlist = res.songs
      console.log(res, '歌单列表')
      this.loading = false
    },
  },
  watch: {
    '$route.query.id': {
      handler (val) {
        this.getMusicDetail(val)
        this.getTrackAll(val)
      }
    },
  }
}
</script>

<style scoped lang="less">
.mains {
  display: flex;
  .right {
    margin-top: 10px;
    width: 1000px;
  }
}
.top {
  overflow: hidden;
  width: 1260px;
  .right {
    margin-top: 10px;
    width: 1000px;
    float: left;
    margin-left: 20px;
    color: #666666;
    .title {
      display: flex;
      align-items: center;
      div {
        width: 34px;
        height: 20px;
        line-height: 20px;
        padding-left: 2px;
        float: left;
        font-size: 14px;
        border: 1px solid #ec4141;
        border-radius: 3px;
        color: #ec4141;
      }
      h2 {
        font-size: 16px;
        padding-left: 10px;
        color: #333333;
      }
    }
    .author {
      margin-top: 10px;
      display: flex;
      align-items: center;
      overflow: hidden;
      img {
        float: left;
        display: block;
        width: 26px;
        height: 26px;
        border-radius: 13px;
      }
      p {
        float: left;
        font-size: 12px;
        margin-left: 10px;
        margin-right: 5px;
        color: #507daf;
      }
      span {
        float: left;
        font-size: 13px;
        margin-left: 10px;
      }
    }
    .buttons {
      display: flex;
      align-items: center;
      height: 30px;
      margin-top: 10px;
      button {
        display: block;
        float: left;
        padding-left: 34px;
        padding-right: 16px;
        margin-right: 10px;
        height: 30px;
        color: #fff;
        background-color: #ec4141;
        border: none;
        border-radius: 15px;
        line-height: 30px;
        font-weight: bold;
        font-size: 15px;
        position: relative;
        &:hover {
          opacity: 0.9;
          background-color: #dcdcdc;
        }
        .cc {
          display: block;
          position: absolute;
          top: 5px;
          left: 0px;
          width: 18px;
          height: 18px;
          margin-left: 14px;
        }
      }
      .bofang {
        background-color: #fff;
        border: 1px solid #d9d9d9;
        color: #000;
        font-weight: normal;
      }
    }
    .biaoqian {
      overflow: hidden;
      margin-top: 6px;
      font-size: 14px;
      span {
        float: left;
        color: #000;
      }
      p {
        float: left;
        color: #507daf;
        margin-left: 7px;
      }
    }
    .music {
      display: flex;
      align-items: center;
      overflow: hidden;
      margin-top: 6px;
      font-size: 14px;
      span {
        float: left;
        color: #000;
      }
      p {
        float: left;
        text-align: center;
        margin-left: 7px;
        margin-right: 10px;
      }
    }
    .intro {
      overflow: hidden;
      margin-top: 6px;
      font-size: 14px;
      span {
        float: left;
        color: #000;
      }
      p {
        width: 460px;
        float: left;
        margin-left: 7px;
        white-space: nowrap; /*不换行强制文本在一行显示*/
        overflow: hidden; /*超出盒子宽度部分文字被隐藏*/
        text-overflow: ellipsis; /*当文本溢出包含元素时发生的事情 ellipsis*/
      }
    }
  }
}
.lists {
  margin-left: -50px;
}
</style>